# 定义
import pyautogui
import win32gui
from ultralytics import YOLO

from yolo2 import 检测框模块
from yolo2.find_class_module import find_class_and_perform_action
from yolo4.yolo8瞄准模板 import AimbotModule

# 加载 YOLOv8n 模型并指定使用GPU .to('cuda')
model = YOLO(r"H:\yol\yolo\v11\runs\detect\train18\weights\best.pt")

hwnd = 检测框模块.find_window()
if hwnd is None:
    print("未找到标题中包含'梦幻西游'的窗口")
else:
    left, top, right, bottom = win32gui.GetWindowRect(hwnd)
    window_width = right - left
    window_height = bottom - top
    def action_a():
        pyautogui.hotkey('alt', 'e')
    find_class_and_perform_action(hwnd, model, 18, action_a)
tasks = [
    {
        "target_class": 18,
        "success_class": 19,
        "refresh_keys": ['f9'],
        "click_offset": (0, 0),
        "click_type": 2
    },
    {
        "target_class": 19,
        "success_class": 9,
        "refresh_keys": [],
        "click_offset": (0, 1),
        "click_type": 1
    },
    {
        "target_class": 9,
        "success_class": 11,
        "refresh_keys": [],
        "click_offset": (0, 0),
        "click_type": 1
    },
    {
        "target_class": 11,
        "success_class": 14,
        "refresh_keys": [],
        "click_offset": (0, 1),
        "click_type": 1
    },
    {
        "target_class": 14,
        "success_class": 13,
        "refresh_keys": [],
        "click_offset": (0, 100),
        "click_type": 1
    },
    {
        "target_class": 13,
        "success_class": 10,
        "refresh_keys": [],
        "click_offset": (-10, 1),
        "click_type": 1
    },
    {
        "target_class": 10,

        "success_class": 6,
        "refresh_keys": [],
        "click_offset": (-10, 1),
        "click_type": 1
    }
]

aimbot = AimbotModule(tasks)
# 可以调整任务间的延迟时间
aimbot.start(distance_threshold=50, delay_between_tasks=2)